package cl.ccs.migracionbcmc.validators;

import cl.ccs.migracionbcmc.util.Messages;
import cl.ccs.migracionbcmc.validators.exception.ValidatorException;


public class Contact extends Validator {
    
    private final static String SUBJECT_PATTERN = "^.{3,20}";
    private final static String CONTENT_PATTERN = "^.{3,200}";
    
    private String subject;
    private String content;
    
    public Contact(String subject, String content) throws ValidatorException
    {
        super();
        setSubject(subject);
        setContent(content);
    }
    
    private void setSubject(String subject) throws ValidatorException
    {
        if (match(subject, SUBJECT_PATTERN)) {
            this.subject = subject;
        } else {
            throw new ValidatorException(Messages.CONTACT_US_FIELDS_FORMAT_ERROR);
        }
        
    }

    public String getSubject() {
        return subject;
    }

    private void setContent(String content) throws ValidatorException
    {
        if (match(content, CONTENT_PATTERN)) {
            this.content = content;
        } else {
            throw new ValidatorException(Messages.CONTACT_US_FIELDS_FORMAT_ERROR);
        }
    }
    
    public static boolean isSubjectValid(String subject) {
        return match(subject, SUBJECT_PATTERN);
    }
    
    public static boolean isContentValid(String content) {
        return match(content, CONTENT_PATTERN);
    }

    public String getContent() {
        return content;
    }
}
